-
Notifications
You must be signed in to change notification settings - Fork 17
Add ASDFCutout to General Architecture #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ddd1f7d to
872d8f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good! It's evolved a bit from the changes in asdf-generalization but I do think it's a better direction. Also as far as changing the tests, I do also think that is necessary as the underlying architecture is changing as well and should be captured.
I also agree with the necessity of changing the API in general, with the general revamping of astrocut I don't really see changes being avoidable.
havok2063
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good. I think it's fine to change the API now. This code is still in development, and not being used much. Better to make all these changes now before Roman comes online and we get users/tools actively using this.
Regarding point 3, I think it's useful to be able to access the Cutout2D object. I find it useful for inspection and troubleshooting. I do think the return objects from the user-level cutout classes, like FITSCutout, ASDFCutout, should be consistent with each other. Cutout2D doesn't need to be a default user output though. Maybe we can store the cutout as an attribute, and document how to access it.
Along those same lines, we should consider any other items we want to make attributes or properties to make accessible to the user. I think there's two workflows to consider: one where users just make a cutout and get the output file in one go, and one where users make a cutout, but want to interact with it within the same session.
| def _get_cloud_http(self, input_file: Union[str, S3Path]) -> str: | ||
| """ | ||
| Get the HTTP URL of a cloud resource from an S3 URI. | ||
| Parameters | ||
| ---------- | ||
| input_file : str | S3Path | ||
| The input file S3 URI. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we also have other missions in the cloud, JWST, HST, TESS, we may want to consider moving this into ImageCutout, so we can eventually take advantage of cloud cutouts of those missions, or fits files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FITSCutout is actually already cloud-enabled. It is a bit awkward, but the reason that _get_cloud_http is here is because the asdf.open function can't handle S3 URIs in the same way that fits.open can.
astrocut/ASDFCutout.py
Outdated
| The FITS WCS of the image. This is approximated from the GWCS object. | ||
| gwcs : `~gwcs.wcs.WCS` | ||
| The GWCS of the image. | ||
| pixel_coords : tuple | ||
| The pixel coordinates closest to the center of the cutout. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this Return needs updating to match what is returned, or vice versa.
| img_cutout = Cutout2D(data, | ||
| position=pixel_coords, | ||
| wcs=wcs, | ||
| size=(self._cutout_size[1], self._cutout_size[0]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the plan again for using Cutout2D as the main cutout method, in FITSCutout or ImageCutout? It would be nice if we could consolidate the cutout functionality and have a consistent approach across filetypes, missions. Are there roadblocks to this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the ultimate goal is to have Cutout2D be the main method in ImageCutout! The issue with FITSCutout is that astropy couldn't handle HDUList.section objects when creating partial cutouts. Using the section attribute is a huge speed-up, so I elected to prioritize that over using Cutout2D. I put in a PR to fix this that was recently merged, but I'm not sure when the next astropy release will be.
| def asdf_cut(input_files: List[Union[str, Path, S3Path]], | ||
| ra: float, | ||
| dec: float, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to the other xxx_cut functions, can we add a sentence to the docstring that says we're retaining this for backwards compatibility?
|
Just make sure when we merge things into main, we can't break the existing tutorial we delivered for Roman asdf cutouts, or we need to modify the tutorial to work with any changes that impact it. Any previously delivered requirement may be tested with every Build. |
I'll create a draft MR with |
|
Thanks. Does the Roman Nexus pin on a particular astrocut version? If it does, we could also tell them not to update the version of astrocut in Nexus until we know the notebook tutorial is updated to support any backwards-incompatible changes to whatever the newer astrocut version is. I think long-term when the mission is live that's not a great way to go, since ideally the Nexus is always making the latest stable versions of packages available as quickly as possible to users, but while things need to be stable for testing prior to launch it might be useful / already being done? |
|
I would assume that the Roman Nexus does have specific versions pinned in the same way that TIKE does. I'm not sure how to find them though, and I don't see anything in the |
|
While addressing Brian's comments, I've run into another design choice that I'm conflicted about. Previously, I personally prefer I could add another parameter, something like |
|
In what ways would changing |
|
|
bcb6fad to
8947c23
Compare
|
I've given this some more thought. Here are my two cents. IMO, as a user, the way that I'd want to work with I also would want a convenience function that combines all those steps into a single function that I could run easily, for when I trust the code or don't care. It creates the cutout, saves the file, and returns me the filepath on disk. This is what the This could create some potential repeated boilerplate code between |
|
I love this idea! It took me a while to change things around, but I got something working that majorly decreases the complexity of these classes by moving the logic for writing files into separate functions ( Added attributes for
Added attributes for
For You had some great ideas for other features like plotting, exposing a WCS, etc. I'm still thinking about how features like these will work best given that the classes take multiple input files and can generate a lot of different cutouts at once. I could save the WCS for every cutout, but that seems like a waste of resources. I could also add these things as separate functions, but require a single cutout to be passed in as input? I'm not sure. |
|
I think I came up with a pretty decent solution! I added a nested class,
Another change I made is how |
|
I'll respond briefly to your comments here, and then do a full PR review in a bit.
Yeah I'm not sure if we need to have all class methods support batch mode. I imagine using the classes themselves mostly on a per image/cutout basis for inspection, where each method works on a single cutout. I hadn't fully appreciated nor thought about only working in a batch mode. We may want to brainstorm a bit more on some workflows. I feel most use cases of batching cutouts would be to run them via the convenience functions to return to later, and less via the interactive class instance itself. One scenario might be a user has a bunch of images they want to make cutouts from. They instantiate one in FITSCut to test and inspect the cutout, check settings etc. They then run the whole set in batch mode. Later they want to spot check some of the cutout files. It would be great if they could reload a cutout file via FITSCut after-the-fact to inspect and display. This may change the scope of what Astrocut should do though. If they don't already, I think the cutout files should contain metadata about the original source file and the cutout info in its header. In principle then one could do something like |
havok2063
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me.
Adding the
ASDFCutoutclass as a child ofImageCutout. This one actually does change the existing API in a few ways:asdf_cutandASDFCutoutin the same way that you can withfits_cut.output_fileparameter inasdf_cutis now deprecated.Cutout2Dobject whenmemory_only=True,ASDFCutoutreturnsasdf.AsdfFileobjects by default andHDUListobjects ifoutput_format='fits'. (I'm still a little conflicted on this, actually. Would it be more valuable to return theCutout2Dobjects? Should we have a parameter so users can choose?)I don't love that these will change the API, but
asdf_cutis still very new and I would guess that there's not a large number of people using it yet. These changes are also kind of unavoidable if we wantasdf_cutto be able to handle multiple input files at once. I'd love to hear any thoughts that you might have on this! Once this is merged and released, I'll have to update the Roman cutouts notebook on the science platform.Some other changes/additions: